#ifndef __DRV_CAN_H__
#define __DRV_CAN_H__

#ifdef __cplusplus
extern "C" {
#endif

/*=============================Include========================================*/
#if defined(USE_HAL_STM32F4)
#include "stm32f4xx_hal.h"
#endif
/*==============================ExportedMacros================================*/
// 滤波器编号
#define CAN_FILTER(x) ((x) << 3)

// 接收队列
#define CAN_FIFO_0 (0 << 2)
#define CAN_FIFO_1 (1 << 2)

// 标准帧或扩展帧
#define CAN_STDID (0 << 1)
#define CAN_EXTID (1 << 1)

// 数据帧或遥控帧
#define CAN_DATA_TYPE (0 << 0)
#define CAN_REMOTE_TYPE (1 << 0)

/*=============================ExportedTypes==================================*/
typedef struct can_rx_buffer {
	CAN_RxHeaderTypeDef header;
	uint8_t data[8];
} can_rx_buffer_t;

typedef void (*can_call_back)(can_rx_buffer_t *);

typedef struct can_manager {
	CAN_HandleTypeDef *hcan;
	can_rx_buffer_t rx_buffer;
	can_call_back call_back_function;
} can_manager_t;

/*=============================ExportedDefinitions============================*/
extern CAN_HandleTypeDef hcan1;
extern CAN_HandleTypeDef hcan2;

extern can_manager_t can1_manager;
extern can_manager_t can2_manager;

extern uint8_t can1_0x1fe_tx_data[8];
extern uint8_t can1_0x1ff_tx_data[8];
extern uint8_t can1_0x200_tx_data[8];
extern uint8_t can1_0x2fe_tx_data[8];
extern uint8_t can1_0x2ff_tx_data[8];
extern uint8_t can1_0x3fe_tx_data[8];
extern uint8_t can1_0x4fe_tx_data[8];

extern uint8_t can2_0x1fe_tx_data[8];
extern uint8_t can2_0x1ff_tx_data[8];
extern uint8_t can2_0x200_tx_data[8];
extern uint8_t can2_0x2fe_tx_data[8];
extern uint8_t can2_0x2ff_tx_data[8];
extern uint8_t can2_0x3fe_tx_data[8];
extern uint8_t can2_0x4fe_tx_data[8];

/*=============================ExportedFunctionDeclarations===================*/
void can_init(CAN_HandleTypeDef *hcan, can_call_back call_back_function);
uint8_t can_send_data(CAN_HandleTypeDef *hcan, uint16_t can_ID, uint8_t *data,
                      uint16_t length);

#ifdef __cplusplus
}
#endif

#endif

/*========================COPYRIGHT(C) CCUT-DAMOCLES==========================*/

